package avicit.bdp.dms.das.rest;

import avicit.bdp.dms.das.dto.BdpDasCategoryDTO;
import avicit.bdp.dms.das.dto.BusinessDTO;
import avicit.bdp.dms.das.service.BusinessService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "业务对象Rest接口")
@RequestMapping("/api/bdp/dms/das/business")
public class BusinessRest {

    @Autowired
    private BusinessService businessService;

    @ApiOperation(value = "新增业务对象")
    @PostMapping("/insertBusiness")
    public ResponseMsg<BusinessDTO> insertBusiness(@RequestBody BusinessDTO businessDTO) {
        ResponseMsg<BusinessDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(businessService.insertBusiness(businessDTO));
        return responseMsg;
    }


    @ApiOperation(value = "修改业务对象")
    @PutMapping("/updateBusiness")
    public ResponseMsg<String> updateBusiness(@RequestBody BusinessDTO businessDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        businessService.updateBusiness(businessDTO);
        return responseMsg;
    }

    @ApiOperation(value = "删除业务对象")
    @ApiParam(value = "主键id", name = "id", required = true)
    @DeleteMapping
    public ResponseMsg<Boolean> deleteLayer(@RequestBody String id) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        businessService.deleteBusiness(id);
        return responseMsg;
    }

    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "分类ID", name = "categoryId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "查询关键词", name = "keyWords", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "类型", name = "type", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping(value = "/getPageList")
    public ResponseMsg<QueryRespBean<BusinessDTO>> getPageList(
            @RequestParam(required = false) String categoryId,
            @RequestParam(required = false) String keyWords,
            //@RequestParam(required = false) Integer status,
            @RequestParam(required = false) Integer type,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<BusinessDTO>> responseMsg = new ResponseMsg<>();

        QueryRespBean<BusinessDTO> queryRespBean = businessService.getPageList(categoryId, keyWords,type, pageNo,
                pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "查询业务实体树形")
    @GetMapping("/findBusinessTree")
    public ResponseMsg<List<BdpDasCategoryDTO>> findBusinessTree() {
        ResponseMsg<List<BdpDasCategoryDTO>> responseMsg = new ResponseMsg<>();
        List<BdpDasCategoryDTO> result = businessService.findBusinessTree();
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @ApiParam(value = "id", name = "id", required = true)
    @GetMapping("/{id}")
    public ResponseMsg<BusinessDTO> queryById(@PathVariable String id) {
        ResponseMsg<BusinessDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(businessService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "启用/停用")
    @PostMapping("/updateStatus")
    public ResponseMsg<Boolean> updateStatus(@RequestBody BusinessDTO businessDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        businessService.updateStatus(businessDTO.getIds(), businessDTO.getStatus());
        return responseMsg;
    }

    /**
     * 查看图形界面
     * @param categoryId
     * @return
     */
    @ApiOperation(value = "查看图形界面")
    @ApiImplicitParam(value = "末级节点分类ID", name = "categoryId", dataType = "String")
    @GetMapping("/searchBusinessImage")
    public ResponseMsg<Map<String, Object>> searchBusinessImage(
            @RequestParam String categoryId) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(businessService.searchBusinessImage(categoryId));
        return responseMsg;
    }


    /**
     *@更新坐标
     *@参数
     *@返回值
     */
    @ApiOperation(value = "修改业务对象")
    @PutMapping("/updatePosition")
    public ResponseMsg<String> updatePosition(@RequestBody BusinessDTO businessDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        businessService.updatePosition(businessDTO);
        return responseMsg;
    }
}
